﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace NoteSystem.Utils
{
    public class DbHelper
    {
        /// <summary>
        /// 查询数据库的信息，返回一个容器
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>

        public  static DataSet Query(string sql)
        {
            SqlConnection connection = new SqlConnection("server=(local);uid=sa;pwd=123456;database=KeDa2025");
            SqlDataAdapter da = new SqlDataAdapter(sql, connection);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds;
        }

        public static int ExecuteSql(string sql)
        {
            //写库Command
            SqlConnection connection = new SqlConnection("server=(local);uid=sa;pwd=123456;database=KeDa2025");
            //Command负责数据库的写操作（delete,update,insert）参数1：操作语句，参数2：数据库链接
            SqlCommand cmd = new SqlCommand(sql, connection);
            //打开数据
            connection.Open();
            int flag = cmd.ExecuteNonQuery();
            connection.Close();
            return flag;
        }

    }
}